using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using User.Domain.Entities;
using User.Domain.ValueObjects;

namespace User.Infrastructure.Configurations
{
    public class UserConfiguration: IEntityTypeConfiguration<UserProfile>
    {
        public void Configure(EntityTypeBuilder<UserProfile> builder)
        {
            // 表名
            builder.ToTable("UserProfile");

            // 主键默认约定Id，不在你示例中，我假设有Id
            builder.HasKey(u => u.Id);

            builder.Property(u => u.NickName)
                .IsRequired(false)
                .HasMaxLength(100);


            // CreatedDate 映射
            builder.Property(u => u.CreatedAt)
                .IsRequired();

           
            // LastLoginDate 映射（可空）
            builder.Property(u => u.LastLoginTime)
                .IsRequired(false);

            // AvatarUrl 映射（可空）
            builder.Property(u => u.AvatarUrl)
                .HasMaxLength(500)
                .IsRequired(false);

            // PhoneNumber 转换器示例（假设 PhoneNumber 是值对象）
            var phoneNumberConverter = new ValueConverter<PhoneNumber, string>(
                v => v.ToString(),
                v => PhoneNumber.From(v)
            );
            builder.Property(u => u.PhoneNumber)
                .HasConversion(phoneNumberConverter)
                .HasMaxLength(50)
                .IsRequired(false);

            // Address 映射（可空）
            builder.Property(u => u.Address)
                .HasMaxLength(500)
                .IsRequired(false);

            
        }
    }
}